import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-13
 * Time: 23:47
 */
public class Test51 {
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode() {

        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    static int ret = Integer.MIN_VALUE;

    public static int maxPathSum(TreeNode root) {
        dfs(root);
        return ret;
    }

    public static int dfs(TreeNode root) {
        if(root == null) {
            return 0;
        }
        int left = dfs(root.left);
        int right = dfs(root.right);

        ret = Math.max(ret,left+right+root.val);

        return Math.max(0,Math.max(left,right)+root.val);
    }

    public static TreeNode build(String s) {
        String input = s.replace("[", "").replace("]", "");
        String[] parts = input.split(",");
        Integer[] num = new Integer[parts.length];

        for (int i = 0; i < parts.length; i++) {
            if (!parts[i].equals("null")) {
                num[i] = Integer.parseInt(parts[i]);
            } else {
                num[i] = null;
            }
        }

        // 重点
        if (num.length == 0 || num[0] == null) {
            return null;
        }
        TreeNode root = new TreeNode(num[0]);
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        int index = 1;

        while (!q.isEmpty() && index < num.length) {
            TreeNode cur = q.poll();

            if (index < num.length && num[index] != null) {
                cur.left = new TreeNode(num[index]);
                q.offer(cur.left);
            }
            index++;

            if (index < num.length && num[index] != null) {
                cur.right = new TreeNode(num[index]);
                q.offer(cur.right);
            }
            index++;
        }
        return root;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        TreeNode root = build(s);
        int ret = maxPathSum(root);
        System.out.println(ret);
    }
}
